/**
 * cn.ucox.web.framework.exception.CacheInvalidationException
 *
 * @author chenw
 * @create 16/2/4.10:43
 * @email javacspring@hotmail.com
 */

package cn.ucox.web.ms.exception;

import java.util.HashMap;

/**
 * 缓存异常
 *
 * @author chenw
 * @create 16/2/4 10:43
 * @email javacspring@gmail.com
 */
public class CacheInvalidationException extends BasicException {

    private int action;
    private String cacheKey;
    private String cacheValue;

    public CacheInvalidationException(Action action, String cacheKey) {
        this(action, cacheKey, null);
    }

    public CacheInvalidationException(int errorCode, String message) {
        super(errorCode, message);
    }

    public CacheInvalidationException(Action action, String cacheKey, String cacheValue) {
        this(action, "数据缓存异常", cacheKey, cacheValue);
    }

    public CacheInvalidationException(Action action, String message, String cacheKey, String cacheValue) {
        this(CODE_CACHE_INVALIDATION_EXCEPTION, message);
        this.action = action.value();
        this.cacheKey = cacheKey;
        this.cacheValue = cacheValue;
    }


    @Override
    public Object getData() {
        return new HashMap<String, Object>() {{
            put("action", action);
            put("key", cacheKey);
            if (null != cacheKey)
                put("value", cacheValue);
        }};
    }
}
